/////////////////////////////////////////////////page_carRentalOrder//////////////////
$(document).on("pageInit", "#page_carRentalOrder", function(e, pageId, $page) {
    my.givetitle('车辆出租订单');
	 key=my.get_key(my.getCookie('token'))
      	    	    var loading = false;
                    var carRentalOrderType=1
                    var pageNow=1
                    $('.infinite-scroll-preloader').show();
                    $('.infiniteOver').hide()
      	    	    var orderActiveList=my.getCarRentalOrderList(my.getCookie('id'),'','',key,1)
      	    	    console.log(orderActiveList)
//    	    	    var orderList=orderActiveList.cartime_list
//    				orderList.sort(function(x,y){
//    					return x.cartime_start.substr(0,10).replace('-','').replace('-','')-y.cartime_start.substr(0,10).replace('-','').replace('-','')
//    				})
      	    	   setTimeout(function(){
      	    	   if(orderActiveList!=''){
      	    	   	$('.carRental-order-list').empty()
      	    	   for(i=0;i<orderActiveList.cartime_list.length;i++){
      	    	   	  var list='<li id="'+orderActiveList.cartime_list[i].cartime_id+'"><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].cartime_id+'</span><span>车时编号</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].cars_name+' '+orderActiveList.cartime_list[i].models_name+'</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].car_plate+'</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].stores_name+'</span><span>原地还车</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].total_revenue+'</span><span>当前收益</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].order_count+'</span><span>订单数</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].cartime_start+'</span><span>开始时间</span></div><div class="carR-ok-b"><span>'
                                +orderActiveList.cartime_list[i].cartime_end+'</span><span>结束时间</span></div><div class="carR-ok-b order-list-more"><span>'
           	    	            +orderActiveList.cartime_list[i].status_dec+'<img src="/h5car/img/icon/sj.png"></span></div></li>'
           	           $('.carRental-order-list').append(list)
      	    	   }
      	    	    if(orderActiveList.cartime_list.length<10){
      	    	        $.detachInfiniteScroll($('.infinite-scroll'));
                        $('.infinite-scroll-preloader').hide();
                        $('.infiniteOver').show()
      	    	     }else{
      	    	     	 $.attachInfiniteScroll($('.infinite-scroll'));
                         $('.infinite-scroll-preloader').show();
                         $('.infiniteOver').hide()
      	    	     }
      	    	   $('.carRental-order-list li').click(function(){
      	    	   	sessionStorage.cartime_id=$(this).attr('id')
      	    	   //	$.router.loadPage("carRentalOrderDetails.html");
                       $.router.load(carRentalOrderDetailsUrl,true);
      	    	   })
      	    	   }else{
      	    	     	$.detachInfiniteScroll($('.infinite-scroll'));
                        $('.infinite-scroll-preloader').hide();
                        $('.infiniteOver').show()
      	    	   }
      	    	   },1000)

      	    	   //获取行程中订单开始
      	    	   $('.orderActive').click(function(){
      	    	   	carRentalOrderType=1
      	    	   	pageNow=1
      	    	   	$(this).siblings('span').removeClass('active')
      	    	   	$(this).addClass('active')
      	    	   	$('.carRental-order-list').empty()
      	    	   	$('.infinite-scroll-preloader').show();
                    $('.infiniteOver').hide()
      	    	   	var orderActiveList=my.getCarRentalOrderList(my.getCookie('id'),'','',key,1)
      	    	    setTimeout(function(){
      	    	   	if(orderActiveList!=''){
      	    	     for(i=0;i<orderActiveList.cartime_list.length;i++){
      	    	   	  var list='<li id="'+orderActiveList.cartime_list[i].cartime_id+'"><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].cartime_id+'</span><span>车时编号</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].cars_name+' '+orderActiveList.cartime_list[i].models_name+'</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].car_plate+'</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].stores_name+'</span><span>原地还车</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].total_revenue+'</span><span>当前收益</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].order_count+'</span><span>订单数</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].cartime_start+'</span><span>开始时间</span></div><div class="carR-ok-b"><span>'
                                +orderActiveList.cartime_list[i].cartime_end+'</span><span>结束时间</span></div><div class="carR-ok-b order-list-more"><span>'
           	    	            +orderActiveList.cartime_list[i].status_dec+'<img src="/h5car/img/icon/sj.png"></span></div></li>'
           	           $('.carRental-order-list').append(list)
      	    	     }
      	    	     if(orderActiveList.cartime_list.length<10){
      	    	        $.detachInfiniteScroll($('.infinite-scroll'));
                        $('.infinite-scroll-preloader').hide();
                        $('.infiniteOver').show()
      	    	     }else{
      	    	     	 $.attachInfiniteScroll($('.infinite-scroll'));
                         $('.infinite-scroll-preloader').show();
                         $('.infiniteOver').hide()
      	    	     }
      	    	   $('.carRental-order-list li').click(function(){
      	    	      	sessionStorage.cartime_id=$(this).attr('id')
      	    	     	//$.router.loadPage("carRentalOrderDetails.html");
                       $.router.load(carRentalOrderDetailsUrl,true);
      	    	   })
      	    	   }else{
      	    	     	$.detachInfiniteScroll($('.infinite-scroll'));
                        $('.infinite-scroll-preloader').hide();
                        $('.infiniteOver').show()

      	    	        }
      	    	   },1000)
      	    	   })
      	    	   //获取行程中订单结束
      	    	    //获取已完成订单开始
      	    	   $('.orderOver').click(function(){
      	    	   	carRentalOrderType=2
      	    	   	pageNow=1
      	    	   	$(this).siblings('span').removeClass('active')
      	    	   	$(this).addClass('active')
      	    	   	 $('.carRental-order-list').empty()
      	    	   $('.infinite-scroll-preloader').show();
                    $('.infiniteOver').hide()
      	    	   	var orderActiveList=my.getCarRentalOrderList(my.getCookie('id'),'','',key,2)
      	    	    setTimeout(function(){
      	    	   	if(orderActiveList!=''){
      	    	       for(i=0;i<orderActiveList.cartime_list.length;i++){
      	    	   	  var list='<li id="'+orderActiveList.cartime_list[i].cartime_id+'"><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].cartime_id+'</span><span>车时编号</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].cars_name+' '+orderActiveList.cartime_list[i].models_name+'</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].car_plate+'</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].stores_name+'</span><span>原地还车</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].total_revenue+'</span><span>当前收益</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].order_count+'</span><span>订单数</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].cartime_start+'</span><span>开始时间</span></div><div class="carR-ok-b"><span>'
                                +orderActiveList.cartime_list[i].cartime_end+'</span><span>结束时间</span></div><div class="carR-ok-b order-list-more"><span>'
           	    	            +orderActiveList.cartime_list[i].status_dec+'<img src="/h5car/img/icon/sj.png"></span></div></li>'
           	           $('.carRental-order-list').append(list)
      	    	     }
      	    	     if(orderActiveList.cartime_list.length<10){
      	    	        $.detachInfiniteScroll($('.infinite-scroll'));
                        $('.infinite-scroll-preloader').hide();
                        $('.infiniteOver').show()
      	    	     }else{
      	    	     	 $.attachInfiniteScroll($('.infinite-scroll'));
                         $('.infinite-scroll-preloader').show();
                         $('.infiniteOver').hide()
      	    	     }
      	    	     $('.carRental-order-list li').click(function(){
      	    	   	    sessionStorage.cartime_id=$(this).attr('id')
      	    	      	//$.router.loadPage("carRentalOrderDetails.html");
                         $.router.loadPage(carRentalOrderDetailsUrl,true);
      	    	       })
      	    	     }else{

      	    	     	$.detachInfiniteScroll($('.infinite-scroll'));
                        $('.infinite-scroll-preloader').hide();
                        $('.infiniteOver').show()
      	    	   }
      	    	     },1000)

      	    	   })
      	    	   //获取已完成订单结束
      	    	   //获取异常订单开始
      	    	   $('.orderAbnormal').click(function(){
      	    	   	carRentalOrderType=3
      	    	   	pageNow=1
      	    	   	$(this).siblings('span').removeClass('active')
      	    	   	$(this).addClass('active')
      	    	   	$('.carRental-order-list').empty()
      	    	   	$('.infinite-scroll-preloader').show();
                    $('.infiniteOver').hide()
      	    	   	var orderActiveList=my.getCarRentalOrderList(my.getCookie('id'),'','',key,3)
      	    	    setTimeout(function(){
      	    	   	if(orderActiveList!=''){
      	    	       for(i=0;i<orderActiveList.cartime_list.length;i++){
      	    	   	   var list='<li id="'+orderActiveList.cartime_list[i].cartime_id+'"><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].cartime_id+'</span><span>车时编号</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].cars_name+' '+orderActiveList.cartime_list[i].models_name+'</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].car_plate+'</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].stores_name+'</span><span>原地还车</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].total_revenue+'</span><span>当前收益</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].order_count+'</span><span>订单数</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].cartime_start+'</span><span>开始时间</span></div><div class="carR-ok-b"><span>'
                                +orderActiveList.cartime_list[i].cartime_end+'</span><span>结束时间</span></div><div class="carR-ok-b order-list-more"><span>'
           	    	            +orderActiveList.cartime_list[i].status_dec+'<img src="/h5car/img/icon/sj.png"></span></div></li>'
           	           $('.carRental-order-list').append(list)
      	    	       }
      	    	       if(orderActiveList.cartime_list.length<10){
      	    	        $.detachInfiniteScroll($('.infinite-scroll'));
                        $('.infinite-scroll-preloader').hide();
                        $('.infiniteOver').show()
      	    	     }else{
      	    	     	 $.attachInfiniteScroll($('.infinite-scroll'));
                         $('.infinite-scroll-preloader').show();
                         $('.infiniteOver').hide()
      	    	     }
      	    	        $('.carRental-order-list li').click(function(){
      	    	         	sessionStorage.cartime_id=$(this).attr('id')
      	    	     	   // $.router.loadPage("carRentalOrderDetails.html");
                            $.router.load(carRentalOrderDetailsUrl,true);
      	    	         })
      	    	     }else{

      	    	     	$.detachInfiniteScroll($('.infinite-scroll'));
                        $('.infinite-scroll-preloader').hide();
                        $('.infiniteOver').show()

      	    	     }
      	    	   	},1000)
      	    	   })
      	    	   //获取异常订单结束
      	    	   //无限加载
      	    	    $(document).off("infinite").on("infinite", ".page-current .infinite-scroll-carRentalOrder", function() {
                    // 如果正在加载，则退出
                    if (loading) return;
                    pageNow=Math.ceil($('.page-current .carRental-order-list li').length/10+0.01)
                    console.log('pageNow:'+pageNow)
                    loading = true;
                    $('.infinite-scroll-preloader').show();
                    $('.infiniteOver').hide()
                    setTimeout(function() {
                    loading = false;
                    var orderActiveList=my.getCarRentalOrderList(my.getCookie('id'),'10',pageNow,key,carRentalOrderType)
      	    	   	if(orderActiveList!=''){
      	    	   		if(pageNow==1){
      	    	   		   $('.carRental-order-list').empty()
      	    	   		}
      	    	   		console.log('载入条数:'+orderActiveList.cartime_list.length)
      	    	        for(i=0;i<orderActiveList.cartime_list.length;i++){
      	    	   	            var list='<li id="'+orderActiveList.cartime_list[i].cartime_id+'"><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].cartime_id+'</span><span>车时编号</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].cars_name+' '+orderActiveList.cartime_list[i].models_name+'</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].car_plate+'</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].stores_name+'</span><span>原地还车</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].total_revenue+'</span><span>当前收益</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].order_count+'</span><span>订单数</span></div><div class="carR-ok-b"><span>'
           	    	            +orderActiveList.cartime_list[i].cartime_start+'</span><span>开始时间</span></div><div class="carR-ok-b"><span>'
                                +orderActiveList.cartime_list[i].cartime_end+'</span><span>结束时间</span></div><div class="carR-ok-b order-list-more"><span>'
           	    	            +orderActiveList.cartime_list[i].status_dec+'<img src="/h5car/img/icon/sj.png"></span></div></li>'
           	                  $('.carRental-order-list').append(list)
      	    	     }
      	    	     if(orderActiveList.cartime_list.length<10){
      	    	        $.detachInfiniteScroll($('.infinite-scroll'));
                        $('.infinite-scroll-preloader').hide();
                        $('.infiniteOver').show()
      	    	     }
      	    	     $('.carRental-order-list li').click(function(){
      	    	      	sessionStorage.cartime_id=$(this).attr('id')
      	    	     	//$.router.loadPage("carRentalOrderDetails.html");
                         $.router.load(carRentalOrderDetailsUrl,true);
      	    	     })
      	    	     }else{
      	    	     	$.detachInfiniteScroll($('.infinite-scroll'));
                        $('.infinite-scroll-preloader').hide();
      	    	     	$('.infiniteOver').show()
      	    	     }
                   }, 1000);
               });
});